package com.ktjy.pet.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ktjy.pet.domain.TPet;
import com.ktjy.pet.service.ITPetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 宠物Controller
 *
 * @author t382
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/pet/pet")
public class TPetController extends BaseController {
    @Autowired
    private ITPetService tPetService;

    /**
     * 查询宠物列表
     */
    @PreAuthorize("@ss.hasPermi('pet:pet:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPet tPet) {
        startPage();
        List<TPet> list = tPetService.selectTPetList(tPet);
        return getDataTable(list);
    }

    /**
     * 导出宠物列表
     */
    @PreAuthorize("@ss.hasPermi('pet:pet:export')")
    @Log(title = "宠物", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TPet tPet) {
        List<TPet> list = tPetService.selectTPetList(tPet);
        ExcelUtil<TPet> util = new ExcelUtil<TPet>(TPet.class);
        util.exportExcel(response, list, "宠物数据");
    }

    /**
     * 获取宠物详细信息
     */
    @PreAuthorize("@ss.hasPermi('pet:pet:query')")
    @GetMapping(value = "/{petId}")
    public AjaxResult getInfo(@PathVariable("petId") Long petId) {
        return success(tPetService.selectTPetByPetId(petId));
    }

    /**
     * 新增宠物
     */
    @PreAuthorize("@ss.hasPermi('pet:pet:add')")
    @Log(title = "宠物", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TPet tPet) {
        return toAjax(tPetService.insertTPet(tPet));
    }

    /**
     * 修改宠物
     */
    @PreAuthorize("@ss.hasPermi('pet:pet:edit')")
    @Log(title = "宠物", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPet tPet) {
        return toAjax(tPetService.updateTPet(tPet));
    }

    /**
     * 删除宠物
     */
    @PreAuthorize("@ss.hasPermi('pet:pet:remove')")
    @Log(title = "宠物", businessType = BusinessType.DELETE)
    @DeleteMapping("/{petIds}")
    public AjaxResult remove(@PathVariable Long[] petIds) {
        return toAjax(tPetService.deleteTPetByPetIds(petIds));
    }
}
